package GUI;

import javax.swing.JPanel;

import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;

import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JButton;

import entities.EstimationReport;

import MessagePacks.EstReportPack;
import MessagePacks.MessagePack;
import MessagePacks.UpdatePack;

import java.awt.event.ActionListener;
import java.awt.Dimension;
import javax.swing.JTextField;

/**
 *@author Juan Alapin - 324507516
 *@author Giora Yaffe - 036551281
 *@author Shachar Gritzman - 300174026
 *@author Nir Porat - 021515580
*/

public class EstimationReportSend extends EstimatorMenuScreen {

	private static final long serialVersionUID = 1L;
	private MainGUI mainGui;
	private JButton btnSend;
	private EstReportPack report;
	private EstimationReport rep;
	private JTextField timeest;
	private JTextArea Result1;
	private JTextArea Risks;
	private JTextArea LocOfChange;
	private JTextArea Description;
	private JTextArea Limit;
	private UpdatePack updatePhs,time;
	private UpdatePack upExecflag;
	
	public EstimationReportSend(MainGUI mainGui) {
		super(mainGui);
		this.mainGui=mainGui;
		
	
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 884, 42);
		getContentPane().add(panel);
		

		
		JLabel lblLocationOfChange = new JLabel("Location Of Change");
		lblLocationOfChange.setHorizontalAlignment(SwingConstants.RIGHT);
		lblLocationOfChange.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblLocationOfChange.setBounds(127, 66, 185, 23);
		getContentPane().add(lblLocationOfChange);
		
		JLabel lblDescription = new JLabel("Description");
		lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDescription.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblDescription.setBounds(127, 145, 185, 23);
		getContentPane().add(lblDescription);
		
		JLabel lblLimitations = new JLabel("limitations");
		lblLimitations.setHorizontalAlignment(SwingConstants.RIGHT);
		lblLimitations.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblLimitations.setBounds(127, 238, 185, 23);
		getContentPane().add(lblLimitations);
		
		JLabel lblRisks = new JLabel("Risks");
		lblRisks.setHorizontalAlignment(SwingConstants.RIGHT);
		lblRisks.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblRisks.setBounds(127, 317, 185, 23);
		getContentPane().add(lblRisks);
		
		JLabel lblExecutionTimeEstimation = new JLabel("Execution Time Estimation");
		lblExecutionTimeEstimation.setHorizontalAlignment(SwingConstants.RIGHT);
		lblExecutionTimeEstimation.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblExecutionTimeEstimation.setBounds(127, 518, 185, 23);
		getContentPane().add(lblExecutionTimeEstimation);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(350, 73, 204, 49);
		getContentPane().add(scrollPane);
		
		LocOfChange = new JTextArea();
		scrollPane.setViewportView(LocOfChange);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(350, 152, 204, 75);
		getContentPane().add(scrollPane_1);
		
		Description = new JTextArea();
		scrollPane_1.setViewportView(Description);
		
		JScrollPane scrollPane_2 = new JScrollPane();
		scrollPane_2.setBounds(350, 245, 204, 49);
		getContentPane().add(scrollPane_2);
		
		Limit = new JTextArea();
		scrollPane_2.setViewportView(Limit);
		
		JScrollPane scrollPane_3 = new JScrollPane();
		scrollPane_3.setBounds(350, 324, 204, 62);
		getContentPane().add(scrollPane_3);
		
		Risks = new JTextArea();
		scrollPane_3.setViewportView(Risks);
		
		JScrollPane scrollPane_4 = new JScrollPane();
		scrollPane_4.setBounds(350, 407, 204, 100);
		getContentPane().add(scrollPane_4);
		
		Result1 = new JTextArea();
		scrollPane_4.setViewportView(Result1);
		
		JLabel lblEstimationReport = new JLabel("Estimation Report");
		lblEstimationReport.setFont(new Font("Dialog", Font.BOLD, 16));
		lblEstimationReport.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(lblEstimationReport);
		
						
		JLabel Result = new JLabel("Result");
		Result.setHorizontalAlignment(SwingConstants.RIGHT);
		Result.setFont(new Font("Tahoma", Font.PLAIN, 15));
		Result.setBounds(127, 407, 185, 23);
		getContentPane().add(Result);
		
		timeest = new JTextField();
		timeest.setBounds(350, 521, 204, 20);
		getContentPane().add(timeest);
		timeest.setColumns(10);
		
		setBtnSend();

	}

	public JButton getBtnSend() {
		return btnSend;
	}

	public void setBtnSend() {
		btnSend = new JButton("Send");
		btnSend.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int proc= mainGui.process.getprocessID();				
				rep = new EstimationReport(proc, LocOfChange.getText() , Description.getText(), Result1.getText() ,Limit.getText(), Risks.getText(), Integer.parseInt(timeest.getText()));
				EstReportPack report = new EstReportPack(rep);
				updatePhase();
				updateTimeForLevel2();
				mainGui.client.handleMessageFromClientUI(report); 
				btnSend.setEnabled(false);
			}
		});
		btnSend.setBounds(391, 540, 126, 23);
		getContentPane().add(btnSend);
	}
	public void updatePhase(){
		updatePhs = new UpdatePack(MessagePack.updatePhase);
		updatePhs.setPhaseNum(2);
		//updatePhs.setResponOk(1);
		updatePhs.setProcId(mainGui.process.getprocessID());
		mainGui.client.handleMessageFromClientUI(updatePhs);
		upExecflag = new UpdatePack(MessagePack.updateExecTimeFlag);
		upExecflag.setProcId(mainGui.process.getprocessID());
		upExecflag.setResponOk(0);
		mainGui.client.handleMessageFromClientUI(upExecflag);
		
	}
	public void updateTimeForLevel2() {
		time= new UpdatePack(MessagePack.updateleveltime);
		time.setTime(7);
		time.setPhaseNum(2);
		time.setProcId(mainGui.process.getprocessID());
		mainGui.client.handleMessageFromClientUI(time);
	}
	
	
}
